import SceneController, { KeyEventParameters, DirectionCode, SceneState, FingerStyle } from "../../SceneControl";
import HandGridMoveScene from "../HandGridMoveScene";
import UIMrg from "../../../Script/UIMrg";
import GuidePanel from "../../../Script/GuidePanel";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GuideHandScene extends HandGridMoveScene {
    guidePanel: any;

    protected onEnable(): void {
        this.guidePanel = UIMrg.UIMrg.getPanel(GuidePanel.GuidePanel);
        if (this.guidePanel._act.index == 11) {
            this.onlyGrid = true;
        }
        super.onEnable();
        this.startScene();
        this.tscene.sceneState = SceneState.normal;
        this.tscene.apply();
        this.setSiteByNode(this.guidePanel._target);
    }

    protected addBtnEventKeyDown(para: KeyEventParameters): void {
        if (para.DirectionCode === DirectionCode.ENTER) {
            let btn = this.nodeGrid[this.currSite.x][this.currSite.y];
            if (btn == this.guidePanel._target) {
                this.catchNode = btn;
            }
        }
    }

    protected resetBtnPos(offset?: cc.Vec3): void {
        let descScene = SceneController.instance.scenes.find(item => item.sceneName == "desc");
        if (descScene) {
            let txtName = cc.find("frame/txtName", descScene.sceneNode).getComponent(cc.Label);
            if (txtName.string == "交换") {
                super.resetBtnPos(offset);
                this.tscene.fingerStyle = FingerStyle.hand;
            } else {
                super.resetBtnPos(cc.v3(0, 0));
                this.tscene.fingerStyle = FingerStyle.finger;
            }
        } else {
            super.resetBtnPos(offset);
        }
    }
}
